{%- macro form_field_label(field) -%}
    <label class="control-label" for="{{ field.id }}">{{ field.label.text }}
    {%- if field.flags.required -%}
        <abbr title="This field is required">*</abbr>
    {%- endif %}
	</label>
{% endmacro %}

{%- macro form_field_description(field) -%}
    {% if field.description %}
        <span class="descr">{{ field.description }}</span>
    {% endif %}
{%- endmacro -%}

{%- macro form_field_errors(field) -%}
    {% if field.errors %}
        {%- for error in field.errors -%}
		<span rel="popover" data-content="{{ error }}" data-title="Oups!" data-placement="top" class="error-boubble"></span>
        {%- endfor -%}
    {% endif %}
{%- endmacro -%}

{%- macro form_field_boolean(field) -%}
	<div class="input">
		{{ form_field_errors(field) }}
		<label class="checkbox">
			{{ field(**kwargs) }}
			<span>{{ field.label.text }}</span>
			{{ form_field_description(field) }}
		</label>
	</div>
{%- endmacro -%}

{%- macro form_field_radio(field) -%}
    {% for f in field %}
    <div class="well well-small">
    <label class="radio">
        <input name="{{ f.name }}" id="{{ f.id }}" value="{{ f.data }}" type="radio">{{ f.label.text|safe }}
    </label>
    </div>
    {% endfor %}
{%- endmacro -%}

{%- macro action_buttons(submit_title, cancel_title="Back", submit_class="primary") -%}
<div class="form-actions">
	<input type="submit" class="btn btn-primary {{submit_class}}" value="{{submit_title}}">
	&nbsp;
	<button type="reset" class="btn">{{cancel_title}}</button>
</div>
{%- endmacro -%}

{%- macro form_field(field) -%}
	<div class="control-group {{ error if field.errors }}">
    {% if field.type != 'HiddenField' %}
        {% if field.type == 'BooleanField' %}
            {{ form_field_boolean(field, **kwargs) }}
        {% else%}
            {{ form_field_label(field) }}
					<div class="controls" id="{{field.id}}-div">
            {% if field.type == 'RadioField' %}
                {{ form_field_radio(field, **kwargs) }}
            {% elif field.type == 'TextAreaField' %}
                {{ field(class='input-celestra', rows=5, **kwargs)|safe }}
            {% else %}
                {{ field(class='input-celestra', **kwargs)|safe }}
            {% endif %}
            {{ form_field_description(field) }}
            {{ form_field_errors(field) }}
					</div>
        {% endif %}
    {% endif %}
	</div>
{%- endmacro -%}

{%- macro form_fields(fields, class=None, legend=None) -%}
	<fieldset {% if class %}class="{{class}}"{% endif %}>
		{% if legend %}
			<legend>{{legend}}</legend>
		{% endif %}
    {% for field in fields %}
        {% if field.type != "CSRFTokenField" %}
            {{ form_field(field) }}
        {% endif %}
    {% endfor %}
    {{ fields.hidden_tag() }}
  </fieldset>
{%- endmacro -%}

{%- macro text_field(field, placeholder) -%}
    {{ field(class='span3', placeholder=placeholder) }}
    {{ form_field_errors(field) }}
{%- endmacro -%}
